#ifndef TDSPI_H
#define TDSPI_H
#include <map>
#include "ThostFtdcTraderApi.h"
#include "Struct.h"
class TdSpi: public CThostFtdcTraderSpi
{
public:
    TdSpi();    
    void OnFrontConnected();
    void OnRspUserLogin(CThostFtdcRspUserLoginField *Rtn,CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	void OnRspAuthenticate(CThostFtdcRspAuthenticateField *Rtn,CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
    void OnRspSettlementInfoConfirm(CThostFtdcSettlementInfoConfirmField *Rtn, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
    void OnRspQryInvestorPositionDetail(CThostFtdcInvestorPositionDetailField *Rtn, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
    void OnRtnOrder(CThostFtdcOrderField *Rtn);
    void OnRtnTrade(CThostFtdcTradeField *Rtn);
	void OnRtnInstrumentStatus(CThostFtdcInstrumentStatusField *Rtn);
    void OnRspOrderInsert(CThostFtdcInputOrderField *Rtn, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
    void OnRspOrderAction(CThostFtdcInputOrderActionField *Rtn, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
    void OnRspError(CThostFtdcRspInfoField *Rtn, int nRequestID, bool bIsLast);
    void OnFrontDisconnected(int nReason);
    void OnHeartBeatWarning(int nTimeLapse);
	char checkPosition(std::string symbol);
	void setTarget(const Order* order);
	const Order* getTarget();
	bool isClosed();
private:
	Order target;
    std::map<std::string, int> yesterday_position;
    std::map<std::string, int> today_position;
	bool market_close = false;
};

#endif
